package com.hdax.dm.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hdax.dm.beans.Scheduler.DmSchedulerSeatPrice;
import com.hdax.dm.dto.getPriceDto;
import com.hdax.dm.mappers.getPriceMapper;
import com.hdax.dm.mapstucts.getPriceDtoMapper;
import com.hdax.dm.service.DmSchedulerSeatPriceService;
import com.hdax.dm.utils.response.CommonResponse;
import com.hdax.dm.utils.response.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class DmSchedulerSeatPriceServiceImpl extends ServiceImpl<getPriceMapper, DmSchedulerSeatPrice> implements DmSchedulerSeatPriceService {

    @Autowired
    private getPriceDtoMapper getPriceDtoMapper;

    @Override
    public CommonResponse<List<getPriceDto>> getPrice(Map<String,Integer> params) {
        Integer scheduleId = params.get("scheduleId");
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("scheduleId",scheduleId);
        List<DmSchedulerSeatPrice> lists = baseMapper.selectList(queryWrapper);
        List<getPriceDto> dtos = getPriceDtoMapper.toTargetList(lists);

        for (int i = 0; i < lists.size(); i++) {
            Long isHaveSeat = lists.get(i).getSeatNum();
            if (isHaveSeat<=0){
                dtos.get(i).setIsHaveSeat(0L);
            }
        }

        return ResponseUtil.returnSuccess(dtos);
    }

    @Override
    public List<DmSchedulerSeatPrice> DmSchedulerSeatPrice(Integer id) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("scheduleId",id);
        return baseMapper.selectList(queryWrapper);
    }

    @Override
    public DmSchedulerSeatPrice dmprice(Long schedulerId, String arealevel) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("scheduleId",schedulerId);
        queryWrapper.eq("areaLevel",arealevel);

        return baseMapper.selectOne(queryWrapper);
    }
}
